package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.RelationItemData;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.wby.base.AdapterBase;

/**
 * @author Kay
 * @ClassName RelationShipGridAdapter
 * @Description
 * @date 2016-7-14
 * @history 2016-7-14 author: description:
 */
public class RelationShipGridAdapter extends AdapterBase<RelationItemData> {

    private Context mContext;
    private LayoutInflater inflater;
    private int position = -1;
    private String chengwei;

    public RelationShipGridAdapter(Context mContext, String chengwei) {
        this.mContext = mContext;
        this.chengwei = chengwei;
        inflater = LayoutInflater.from(mContext);
    }

    public void setSelected(int i) {
        this.position = i;
    }

    public int getPosition() {
        return position;
    }

    @Override
    protected View getExView(int i, View view, ViewGroup viewGroup) throws Exception {
        if (view == null) {
            view = inflater.inflate(R.layout.relationship_item, null);
        }
        ImageView img = ViewHolder.get(view, R.id.relationship_item_img);
        TextView tv = ViewHolder.get(view, R.id.relationship_item_tv);

        RelationItemData relationItemData = mList.get(i);
        String name = relationItemData.getName();
        int picNomal = relationItemData.getPicNomal();
        int picChecked = relationItemData.getPicChecked();
        //设置默认选中
        if (!AsStrUtils.isEmpty(chengwei) && chengwei.equals(name)) {
            img.setImageResource(picChecked);
            tv.setTextColor(mContext.getResources().getColor(R.color.blue_button_nor));
        } else {
            img.setImageResource(picNomal);
            tv.setTextColor(mContext.getResources().getColor(R.color.content_text_color));
        }

        //设置选中
        if (position > 0 || position == 0) {
            if (position == i) {
                img.setImageResource(picChecked);
                tv.setTextColor(mContext.getResources().getColor(R.color.blue_button_nor));
            } else {
                img.setImageResource(picNomal);
                tv.setTextColor(mContext.getResources().getColor(R.color.content_text_color));
            }

        }

        tv.setText(name);
        return view;
    }

    @Override
    protected void onReachBottom() {

    }
}
